using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AnimationController : MonoBehaviour
{
	private Dictionary<IAnimationTrigger, int> animationProgress = new Dictionary<IAnimationTrigger, int>();

	private readonly WaitForFixedUpdate waitForFixedUpdate = new WaitForFixedUpdate();

	public void StartAnimation(IAnimationTrigger animationTrigger)
	{
		StartCoroutine(Animate(animationTrigger, false));
	}

	public void OverwriteAnimation(IAnimationTrigger animationTrigger)
	{
		if (animationProgress.ContainsKey(animationTrigger))
		{
			animationProgress[animationTrigger] = 0;
			return;
		}
		animationProgress.Add(animationTrigger, 0);
		StartCoroutine(Animate(animationTrigger, true));
	}

	private IEnumerator Animate(IAnimationTrigger animationTrigger, bool overwrite)
	{
		Transform transform = animationTrigger.GetAnimatedTransform();
		int length = animationTrigger.GetAnimationLength();
		float j;
		for (j = 0f; j < (float)length; j += 1f)
		{
			transform.localScale = (2f - j / (float)length) * Vector3.one;
			j = 1f + ((!overwrite) ? j : ((float)animationProgress[animationTrigger]));
			yield return waitForFixedUpdate;
		}
		if (overwrite)
		{
			animationProgress.Remove(animationTrigger);
		}
	}
}
